<%--
  Created by IntelliJ IDEA.
  User: 98248
  Date: 2020/10/12
  Time: 16:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<h2>当前操作：转账。请输入账号和金额后点“转账”按钮</h2>
<form action="" method="post">
    <input type="text" name="myCardNo" value="${cardNo}" readonly/><br>
    转入账号：<input type="text" name="toCardNo" id="toCardNo"/><br>
    转账金额：<input type="text" name="money" id="money"/><br>
    <input type="button" id="tranferButton" value="转账"/>
</form>
<script type="text/javascript" src="${pageContext.request.contextPath }/static/js/jquery.js"></script>
<script type="text/javascript">
    $(function () {
        $("#tranferButton").click(function () {
            //
            var cardNo = $("#toCardNo").val();
            var money = $("#money").val();
            $.ajax({
                url:"${pageContext.request.contextPath }/check",
                type:"get",
                data:{
                    "cardNo":cardNo
                },
                dataType:"json",
                success:function (data) {
                    console.log(data);
                    if(data==null){
                        alert("目标账户不存在！！");
                        return;
                    }
                    if(data.status==2){
                        alert("账户已冻结！！");
                        return;
                    }
                    if(data.balance-money>0){

                    }

                    //验证通过，发起转账
                    $.ajax({
                        url:"${pageContext.request.contextPath }/doTransfer",
                        type:"post",
                        data:{
                            "toCardNo":cardNo,
                            "money":money
                        },
                        dataType:"json",
                        success:function (data) {
                            if(data==true){
                                alert("转账成功！！");

                            }
                        }
                    })
                }
            })
        })
    })
</script>
</body>
</html>
